export const enum2List = (enumItem, valueIsNumber = false) => {
  return Object.entries(enumItem).map(([value, label]) => ({
    label,
    value: Number(value),
  }));
};

export function getDateStrArr(date) {
  const d = new Date(new Date(date).getTime() + 8 * 3600 * 1000); // 处理时区
  return new Date(d)
    .toISOString()
    .split(/[^0-9]/)
    .slice(0, -2);
}

export function getDateStr(date = new Date(), type = "date") {
  const dateArr = getDateStrArr(date);
  if (type === "date") {
    return dateArr.slice(0, 3).join("-");
  } else if (type === "dateTime")
    return `${dateArr.slice(0, 3).join("-")} ${dateArr.slice(3).join(":")}`;
}

export function transformSize(size) {
  if (size > 1024 * 1024) {
    return `${(size / 1024 / 1024).toFixed(2)}M`;
  } else if (size > 1024) {
    return `${(size / 1024).toFixed(2)}K`;
  } else {
    return `${size}字节`;
  }
}